home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / lang_oth / params / params.pro
Text File  |  1986-05-14  |  2KB  |  83 lines

  1. /*
  2.  * param.pro -- 5/6/'86
  3.  *
  4.  * this program demonstrates how to access the command line
  5.  * parameters from a turbo prolog program.  
  6.  *
  7.  * we use a dos function $62 if the version of dos is
  8.  * 3.0 or greater, and function $51 for 2.xx (an undocumented
  9.  * function)  the potential problem is that certain nameless
  10.  * programs install themselves on function $51, so be warned.
  11.  */
  12.  
  13. include "EXAMPL66.PRO" /* This example includes some */
  14.                        /* handy DOS routines */
  15.  
  16. domains
  17.     strlist = string*
  18. predicates
  19.     write_list(strlist)
  20.    
  21. clauses
  22.     write_list([]).
  23.     write_list([H|T]) :-
  24.         write(H, " "),
  25.         write_list(T).
  26.     
  27. predicates
  28.     get_psp(integer)
  29.     get_params(string, integer)
  30.     m_p(string, integer, integer, strlist, strlist)
  31.     cmd_line(integer, strlist)
  32.     append(strlist, strlist, strlist)
  33.  
  34. clauses
  35.     /* get the psp segment 
  36.      * first clause is for version 3.0 or higher
  37.      */
  38.     get_psp(PSP) :-
  39.         dosver(Version),
  40.         Version >= 3.0,    
  41.         !,
  42.         bios($21,reg($6200,0,0,0,0,0,0,0),
  43.                 reg(_,PSP,_,_,_,_,_,_)).
  44.     /* for version 2.xx */
  45.     get_psp(PSP) :-
  46.     !,
  47.         bios($21,reg($5100,0,0,0,0,0,0,0),
  48.                 reg(_,PSP,_,_,_,_,_,_)).
  49.    
  50.     /* get parameter vector */  
  51.     get_params(P_string, PSP) :-
  52.         ptr_dword(P, PSP, $81),
  53.         frontchar(P, _, P_string).
  54.  
  55.     /* split vector into list of strings */
  56.     m_p(P, Ac, Ac, Av, Av) :-
  57.        frontchar(P, C, _),
  58.        char_int(C, N),
  59.        N = 13.
  60.     m_p(P, Ac, T, Av, V) :-
  61.        fronttoken(P, S1, P1),
  62.        !,
  63.        append(V, [S1], V1),
  64.        T1 = T + 1,
  65.        m_p(P1, Ac, T1, Av, V1).
  66.         
  67.     /* make typical argc, argv form for convience */
  68.     cmd_line(Argc, Argv) :-
  69.        get_psp(PSP),
  70.        get_params(P, PSP),
  71.        m_p(P, Argc, 0, Argv, []).
  72.  
  73.     
  74.     append([], X, X).
  75.     append([H|T], L1, [H|L2]) :-
  76.         append(T, L1, L2).
  77.    
  78. goal
  79.     clearwindow,
  80.     cmd_line(Ac, Av),
  81.     write(Ac), nl,
  82.     write_list(Av), nl.
  83.